<?php

class Basket extends AppModel {

    var $alias = 'Basket';
    var $name = 'Basket';
    var $useTable = 'baskets';
    var $hasMany = array(
        'Basketphoto' => array(
            'className' => 'Basketphoto',
            'foreignKey' => 'basket_id',
            'dependent' => true,
        )
    );

    function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
        $parameters = compact('conditions');
        $this->recursive = $recursive;
        $count = $this->find('count', array_merge($parameters, $extra));
        if (isset($extra['group'])) {
            $count = $this->getAffectedRows();
        }
        return $count;
    }

    function setCache_HomeList($limit = 8) {
        $cacheName = 'basket_home';
        $conditions = array(
            'Basket.published' => 1,
        );
        $data = $this->find('all', array(
                    'fields' => 'Basket.id, Basket.title, Basket.status, Basket.alias, Basket.images_small, Basket.price',
                    'conditions' => $conditions,
                    'limit' => $limit,
                    'order' => array(
                        'Basket.id' => 'DESC'
                    )
                ));
        Cache::write($cacheName, $data, 'basket');
    }

}

?>
